package com.lmuse.xmr.foodspotting.db;

import com.lmuse.xmr.foodspotting.model._Article;

import java.util.Arrays;
import java.util.List;

import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.FindListener;

public class ArticlePresenterImpl implements Contract.ArticlePresenter {

    private Contract.ArticleView articleView;

    public ArticlePresenterImpl(Contract.ArticleView articleView) {
        this.articleView = articleView;
    }

    @Override
    public void queryArticle() {
        String[] objectId = {"HvmMhhhk", "bfGB333Q", "N3tb1119"};

        BmobQuery<_Article> query = new BmobQuery<_Article>();
        query.addWhereContainedIn("objectId", Arrays.asList(objectId));
        //执行查询方法
        query.findObjects(new FindListener<_Article>() {
            @Override
            public void done(List<_Article> object, BmobException e) {
                if(e==null){
                    articleView.onQueryArticleSuccess(object);
                }else{
                    String msg = "失败："+e.getMessage()+","+e.getErrorCode();
                    articleView.onQueryArticleFailed(msg);
                }
            }
        });
    }
}
